package com.pmsco.pms.controller;

import java.util.Locale;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pmsco.pms.annotation.LogonRequired;
import com.pmsco.pms.core.constant.PmsConstant;
import com.pmsco.pms.util.PmsLogonRequired;

/**
 * Handles requests for the application home page.
 */
@Controller
public class PmsHomeController extends AbstractPmsController {
	private static final Logger logger = LoggerFactory.getLogger(PmsHomeController.class);
	
	/**
	 * Show user home page
	 */
	@RequestMapping(value = PmsConstant.user_Url)
	public String user(Locale locale, Model model, HttpSession session) {
		logger.info("Browser user home page");
		buildMenuList(session);
		return PmsConstant.user_View;
	}
	
	/**
	 * Show user home page
	 */
	@RequestMapping(value = PmsConstant.home_Url)
	public String home(Locale locale, Model model, HttpSession session) {
		logger.info("Browser user home page");
		buildMenuList(session);
		return PmsConstant.user_View;
	}
	
	/**
	 * Show user logon page
	 */
	@RequestMapping(value = PmsConstant.userLogon_Url)
	@LogonRequired(required = PmsLogonRequired.NONE)
	public String userLogon(Locale locale, Model model, HttpSession session) {
		logger.info("Browser user logon page");
		buildMenuList(session);
		return PmsConstant.userLogon_View;
	}

	/**
	 * Show admin home page
	 */
	@RequestMapping(value = PmsConstant.admin_Url)
	@LogonRequired(required = PmsLogonRequired.NONE)
	public String admin(Locale locale, Model model, HttpSession session) {
		logger.info("Browser admin home page");
		buildMenuList(session);
		return PmsConstant.admin_View;
	}
	
	/**
	 * Show invalid role user page
	 */
	@RequestMapping(value = PmsConstant.invalidRoleU_Url) 
	@LogonRequired(required = PmsLogonRequired.NORMAL_USER)
	public String invalidRoleU(Locale locale, Model model) {
		logger.info("Browser invalid role user page");
		return PmsConstant.invalidRoleU_View;
	}
	
	/**
	 * Show invalid role admin page
	 */
	@RequestMapping(value = PmsConstant.invalidRoleA_Url) 
	@LogonRequired(required = PmsLogonRequired.ADMIN_USER)
	public String invalidRoleA(Locale locale, Model model) {
		logger.info("Browser invalid role admin page");
		return PmsConstant.invalidRoleA_View;
	}

}
